103-bug-notes-not-visible-after-deleting-a-tag-used-for-filtering#111
Conversation
Added a new property `mainData` of type `MainData` to the `UserData` data class. Created a new sealed class `MainData` with the following subtypes: - `Note` - `Achieve` - `Trash` - `Label` (data class with an `id` property) - `Remainder` Each subtype of `MainData` has an `index` property.
This commit introduces a new field `main_screen_type` to the `UserPreferences` proto and updates `UserPreferencesRepository` to support managing the main screen's data type. - Added `main_screen_type` (int64) to `user_preferences.proto`. - Updated `UserPreferencesRepository` to map the stored `main_screen_type` integer to the corresponding `MainData` sealed class (Note, Achieve, Trash, Remainder, Label). - Added `setMainData` function to `UserPreferencesRepository` to update the `main_screen_type` in DataStore.
Added a new field `mainData` to the `MainActivityUiState` data class in `SharedActivityViewModel.kt`. This field is of type `MainData` and defaults to `MainData.Note`. The `mainData` field will be used to determine which main screen content to display (e.g., Notes, Labels).
Added a trailing comma to the `mainData` property in the `UserData` data class. This is a stylistic change for consistency. Also, removed an extra newline from the end of `MainData.kt`.
The `setMainData` function in `UserPreferencesRepository.kt` now accepts a `Long` parameter named `index` instead of a `MainData` object. The function's implementation was updated to directly use the `index` parameter when setting the `mainScreenType` in user preferences.
This commit introduces a new function `setMainData(mainData: Long)` to the `UserDataRepository` interface and its implementation `OfflineFirstUserDataRepository`. This function allows setting a `Long` value, presumably related to main application data, which is then stored via the `userPreferencesRepository`. - Added `suspend fun setMainData(mainData: Long)` to `UserDataRepository.kt` - Implemented `setMainData` in `OfflineFirstUserDataRepository.kt` to call `userPreferencesRepository.setMainData(mainData)`
Removed the `TypeArg` navigation argument from `MainRoute`. The `MainViewModel` now retrieves the main data type from `UserDataRepository` instead of `SavedStateHandle`. This change simplifies the navigation to `MainScreen` and centralizes the logic for determining the content to display. Files affected: - `feature/main/src/main/kotlin/com/mshdabiola/main/navigation/MainNavigation.kt` - `feature/main/src/main/kotlin/com/mshdabiola/main/MainViewModel.kt`
This commit introduces changes to how main data (e.g., Note, Checklist) is handled and improves navigation within the application.
- Modified `SharedActivityViewModel` to correctly initialize `mainData` in `UserData`.
- Added `setMainData` function to `MainActivityViewModel` to allow updating the main data type (Note or Checklist) in `UserDataRepository`.
- Updated `NoteApp` to:
- Use `uiState` from `MainActivityViewModel` to determine the current `mainData` for the `MainNavigation` drawer.
- Call `viewModel.setMainData(it)` when a navigation item in the drawer is selected.
- Navigate to the main screen without passing the type argument, as this is now handled by `setMainData`.
- Removed the `mainArg` property from `NoteAppState` as it's no longer needed for determining the main screen's content type.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
This commit introduces `MainData` into the `MainState` to manage the type of notes being displayed (e.g., standard notes, labeled notes, reminders). - Added `mainData: MainData` property to `MainState.Success`. - `MainViewModel` now observes `userDataRepository.userData` to update `mainData` in `MainState.Success`. - Logic for filtering notes in `MainViewModel` now uses `mainState.mainData` instead of a separate `mainArg` StateFlow. - When `MainState` is initialized to `Success` with an empty list, it now also sets the initial `mainData` fetched from `userDataRepository`.
When a label is deleted in `LabelViewModel`, the `userDataRepository.setMainData` method is now called with `MainData.Note.index`. This ensures that the main screen is updated to reflect the change, likely by navigating to the notes screen.
Modified `SharingStarted.WhileSubscribed` in `MainActivityViewModel.kt` to remove the 5-second timeout. Removed unused imports `TypeArg` and `NoteType` from `NoteAppState.kt`. - `SharingStarted.WhileSubscribed(5_000)` -> `SharingStarted.WhileSubscribed()` in `MainActivityViewModel.kt`
Removed the unused import `com.mshdabiola.model.NoteType` from `UserPreferencesRepository.kt`.
This commit refactors the `MainViewModel.kt` file. - Removed unused imports: `SharingStarted` and `stateIn`. - Simplified conditional logic for updating `_mainState.value` based on `userDataRepository.userData`. - Streamlined the logic for initializing `_mainState.value` within the `init` block by directly checking the current state.
Removed the `androidx.navigation.navOptions` import from `NoteApp.kt` as it was no longer needed.
This commit adds the `setMainData` method to `FakeUserDataRepository` and `TestUserDataRepository`. - In `FakeUserDataRepository`, `setMainData` now calls the corresponding method in `userPreferencesRepository`. - In `TestUserDataRepository`, `setMainData` updates the `mainData` field of the current `UserData` to `MainData.Note` and emits the updated data. - The initial `UserData` in `TestUserDataRepository` now includes `mainData = MainData.Note`.
Updated the `MainData.Label` class to use its `id` property as its `index`. Previously, it was hardcoded to `0L`. - `MainData.Label(val id: Long) : MainData(0L)` -> `MainData.Label(val id: Long) : MainData(index = id)` in `MainData.kt`
This commit removes several unused files related to data migrations and data classes from the `datastore` module. - Deleted `ChangeListVersions.kt`. - Deleted `IntToStringIdsMigration.kt` and its corresponding test file `IntToStringIdsMigrationTest.kt`. - Deleted `ListToMapMigrationTest.kt`. - Removed `IntToStringIdsMigration` from the `DataStoreModule.kt` as it's no longer needed.
This commit updates `OfflineFirstUserDataRepositoryTest.kt` to include `mainData` in the `UserData` initialization. - Added `MainData.Label(0)` as the initial value for the `mainData` property in the `UserData` object within the test setup.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #111 +/- ##
==========================================
+ Coverage 0.86% 0.89% +0.02%
==========================================
Files 158 156 -2
Lines 6840 6843 +3
Branches 537 539 +2
==========================================
+ Hits 59 61 +2
+ Misses 6772 6769 -3
- Partials 9 13 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/describe |
|
PR Description updated to latest commit (d0e7e9c) |
PR Type
Enhancement
Description
Added MainData sealed class to manage main screen type.
Updated repositories and view models to support MainData.
Improved UI to reflect the selected MainData.
Removed unused code and improved code style.
Changes walkthrough 📝
14 files
Added setMainData function and updated uiState flowAdded mainData to SharedActivityUiStateUpdated NoteApp to use MainData and removed unused codeUpdated onDelete function to set MainDataAdded mainData to MainStateUpdated MainViewModel to use MainData and removed unused codeAdded setMainData functionAdded setMainData functionAdded setMainData function and updated userData flowCreated MainData sealed classAdded mainData propertyAdded setMainData functionAdded setMainData function and updated userData flowAdded main_screen_type field7 files
Removed unused code and improved code styleRemoved unused code and improved code styleRemoved unused fileRemoved unused fileRemoved unused code and improved code styleRemoved unused fileRemoved unused file1 files
Updated test to include MainData